package com.lt.experiment06.mission02;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LT
 * @version 1.0
 * @PackageName com.lt.experiment06.mission02
 * @ClassName UiPerson
 * @Description to do
 * @date 2021/11/28 18:13
 */
public class Seeker implements Observer,Display{
    List<Observer> obs =null;
    int id;
    int hp;
    int sp;
    int up;

    public Seeker(int id,int hp, int sp, int up) {
        this.id = id;
        this.hp = hp;
        this.sp = sp;
        this.up = up;
    }

    @Override
    public void update(int hp, int sp, int up) {
        obs = new ArrayList<>();
        if (this.hp == hp && this.hp != 0){
            obs.add(new HardwarePerson());
        }
        if (this.sp == sp && this.sp != 0){
            obs.add(new SoftwarePerson());
        }
        if (this.up == up && this.up != 0){
            obs.add(new UiPerson());
        }
        display();
    }

    @Override
    public void display() {

        if (obs.isEmpty()){
            return;
        }
        System.out.print("通知用户"+id +":\n");
        for (Observer ob : obs) {
            ob.update(hp,sp,up);
        }
        System.out.println();
    }
}
